<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    protected $redis;
    protected $p;
    public function _initialize(){
        $redis = getRedis();
        $this->redis = $redis;
        $p = I('post.');
        $this->p = $p;
        
    }

    public function index(){
        success('sdf');
    }

    //注册
    public function sigup(){
        checkParamEmpty(array('username', 'password'));
        $this->redis->hMset('users:'.$this->p['username'],array('password'=> $this->p['password'], 'sigtime'=> time(), 'token'=> time()));
        success('sigok');
    }

    //登录
    public function login(){
        checkParamEmpty(array('username', 'password'));
        $verify = $this->redis->hGet('users:'.$this->p['username'], 'password');
        if($verify && $verify == $this->p['password']){
            $token = $this->redis->hGet('users:'.$this->p['username'], 'token');
            success(array('token'=>$token));
        }
        fail('username or password wrong');
    }

}